﻿using System.Collections.Generic;

namespace DBCore.DB
{
    public class Database
    {

        public string Name { get; set; }
        public string DbType { get; set; }
        public string ConnectionString { get; set; }

        public Database() { }
        public Database(string name, string dbtype, string connectionstring)
        {
            Name = name;
            DbType = dbtype;
            ConnectionString = connectionstring;
        }
        public static Dictionary<string, Database> DBS = new Dictionary<string, Database>();
        static Database()
        {
            var elmts = Config.GetXElements("/databases/*");
            foreach (var elm in elmts)
            {
                var connectionString = elm.Attribute("connectstring").Value;
                var name = elm.Attribute("dbname").Value;
             
                if (!DBS.ContainsKey(name))
                {
                    DBS.Add(name, new Database(name, elm.Attribute("dbtype").Value, connectionString));
                }
                else if(DBS.ContainsKey(name)&&DBS[name].ConnectionString!=connectionString)
                {
                        DBS.Add(name, new Database(name, elm.Attribute("dbtype").Value, connectionString));
                }
            }
        }
    }
}
